<template>
  <!-- 库存组件 -->
  <div class="component-commonStock">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>
            <span><a @click="$router.go(-1)">库存</a> >  查看记录 </span>
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(-1)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe606;</span>返回
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-searchHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe63d;</span> 筛选查询
          </p>
          <div class="right">
            <button @click="findRes">查询</button>
          </div>
        </div>
      </div>
    </div>
    <div class="component-search-box">
      <el-form :inline="true" :model="searchBox" class="demo-form-inline">
        <el-form-item label="输入搜索：">
          <el-input clearable v-model="searchBox.search" placeholder="材料名称"></el-input>
        </el-form-item>
        <el-form-item label="操作类型：" v-if="flag != 0">
          <el-select clearable v-model="searchBox.select" placeholder="全部">
            <el-option v-for="(item,index) in selectList" :key="index" :label="item.const_name" :value="item.const_code"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <span class="demonstration">操作时间：</span>
          <el-date-picker
            v-model="searchBox.valueDate"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            default-time="00:00:00"
            value-format="timestamp">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont" style="margin-right:3px;">&#xe61e;</span>出库/入库记录
          </p>
        </div>
      </div>
    </div>
    <div>
      <el-table
        ref="multipleTable"
        :data="info"
        tooltip-effect="dark"
        style="width: 1100px;margin:0 auto;"
        border
      >
        <el-table-column label="编号" align="center" type="index"></el-table-column>
        <el-table-column label="材料名称" align="center" prop="matName"></el-table-column>
        <el-table-column label="型号" align="center" prop="matModel"></el-table-column>
        <el-table-column label="出/入库单号" align="center" prop="orderNum"></el-table-column>
        <el-table-column label="出/入库数量" align="center" prop="realNum"></el-table-column>
        <el-table-column label="操作类型" align="center" v-if="flag != 0">
          <template slot-scope="scope">
            <span v-if="scope.row.formType == 1">采购单号</span>
            <span v-if="scope.row.formType == 2">甲供材料单号</span>
            <span v-if="scope.row.formType == 3">外部调拨单号</span>
            <span v-if="scope.row.formType == 4">内部调拨单号</span>
            <span v-if="scope.row.formType == 5">退料单号</span>
            <span v-if="scope.row.formType == 6">施工队领料单号</span>
          </template>
        </el-table-column>
        <el-table-column label="使用项目" align="center" prop="proName" v-if="flag != 0"></el-table-column>
        <el-table-column label="操作信息" align="center">
          <template slot-scope="scope">
            {{scope.row.operateDate | timeFilter}}
          </template>
        </el-table-column>
        <el-table-column label="查看详情" align="center" width="120" v-if="flag != 0 && flag != 2">
          <template slot-scope="scope">
            <el-button
              @click="checkData(scope.row)"
              type="text"
              size="small"
              class="iconfont icondelete red"
            >查看单据</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="component-paging" v-if="info.length > 0">
      <div class="table-bottom">
        <div class="bottom-left">
        </div>
        <div class="paging">
          <div class="paging-left">
            <p>
              共
              <span>{{Math.ceil(total/pageSize)}}</span> 页/
              <span>{{total}}</span> 条数据
            </p>
          </div>
          <el-pagination
            background
            @size-change="SizeChange($event,dataInit,currentPage,pageSize)"
            @current-change="CurrentChange($event,dataInit,currentPage,pageSize)"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30]"
            :page-size="pageSize"
            layout="sizes, prev, pager, next, jumper"
            :total="total"
          ></el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: ["flag"],
    data() {
      return {
        checkAlls: false,
        searchBox: {
          search: "",
          select: "",
          valueDate:''
        },
        info: [], //表格内容
        multipleSelection: [], //多选
        // 数据总条数
        total: 1,
        // 每页显示数据的条数
        pageSize: 10,
        // 当前显示的页面页码
        currentPage: 1,
        selectList:[]
      };
    },
    mounted(){
      console.log(this.flag);
      console.log(this.$route.query.info);
      this.dataInit();
      this.optionType();
    },

    methods: {
      dataInit(){
        let that = this;
        let suCb = function(res){
          that.info = res.data.data;
          that.total = res.data.rowCount;
          console.log(res.data)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          matName:that.searchBox.search,
          formType:that.searchBox.select,
          operateDate:that.searchBox.valueDate+"",
          pageSize:that.pageSize,
          pageCurrent:that.currentPage,
          smId:that.$route.query.info,
          deviceNum:that.$route.query.deviceNum
        }
        let palyParam = {
          url: "/api/web/proStoreMaterial/selectStoreMaterialDetail",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //点击查询
      findRes(){
        this.currentPage = 1;
        this.dataInit();
      },
      //操作类型
      optionType(){
        let that = this;
        let suCb = function(res){
          that.selectList = res.data.data;
          console.log(res.data.data)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          object:'OriFormType'
        }
        let palyParam = {
          url: "/api/web/proProject/selectConst",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //点击查看单据
      checkData(val){
        console.log(val.operateType);//（0-入库，1-出库）
        console.log(val.formType);//1-采购单号，2-甲供材料单号，3-外部调拨单号，4-内部调拨单号，5-退料单号，6-施工队领料单号；
        console.log(val.id);//出入库id
        /*
          0-1采购入库
          0-2甲供入库
          0-3外调入库
          0-5退料入库
          0-6施工队领料入库

     ---未完成----施工队退料入库---  04状态未处理---

          1-3外部出库
          1-4内部调拨
          1-5退料出库
          1-6施工队领料
        */
        if(val.operateType == 0 && val.formType == 1){
          this.$router.push({
            name: 'procurementList',
            params: {
              flag: 1,
              id:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 0 && val.formType == 2){
          this.$router.push({
            name: 'armorList',
            params: {
              flag: 1,
              id:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 0 && val.formType == 3){
          this.$router.push({
            name: 'allotMaterialList',
            params: {
              flag: 1,
              id:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 0 && val.formType == 5){
          this.$router.push({
            name: 'salereturnList',
            params: {
              flag: 1,
              id:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 1 && val.formType == 3){
          this.$router.push({
            name: 'extDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 1 && val.formType == 4){
          this.$router.push({
            name: 'alloDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 0 && val.formType == 4){
          this.$router.push({
            name: 'alloDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 1 && val.formType == 5){
          this.$router.push({
            name: 'materoutDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 1 && val.formType == 6){
          this.$router.push({
            name: 'teamDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }else if(val.operateType == 0 && val.formType == 6){
          this.$router.push({
            name: 'teamInDetail',
            params: {
              flag: 1,
              outId:val.id,
              loop:1
            }
          })
        }
      }
    }
  };
</script>

<style scoped>

  /* 搜索栏头部样式 */
  .component-searchHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
  }

  .component-searchHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-searchHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    line-height: 45px;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-searchHeader .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 30px;
  }

  .component-searchHeader .right button {
    padding: 0 15px;
    height: 30px;
    margin: 6px 5px;
    line-height: 30px;
    font-size: 12px;
    color: #666;
    background-color: #fff;
    border: 1px solid #ccc;
  }

  .component-searchHeader .right button:hover {
    background-color: #f3f3f3;
  }

  /* 搜索框主体 */
  .component-search-box {
    width: 1100px;
    height: 60px;
    box-sizing: border-box;
    background-color: #fff;
    border: 1px solid #e4e4e4;
    border-top: none;
    margin: 0 auto;
    text-align: left;
    padding-left: 30px;
    line-height: 60px;
  }

  .component-search-box .el-input__inner {
    height: 35px;
    display: inline-block;
  }

  /* 表头样式 */
  .component-listHeader .search-header {
    width: 1100px;
    box-sizing: border-box;
    border: 1px solid rgba(228, 228, 228, 1);
    background-color: rgba(255, 255, 255, 1);
    margin: 20px auto 0;
    border-bottom: none;
  }

  .component-listHeader .search-header .left-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    background-color: rgba(243, 243, 243, 1);
    height: 45px;
    box-sizing: border-box;
  }

  .component-listHeader .search-header .left-title .left-text {
    width: 20%;
    color: #666;
    font-family: "微软雅黑";
    font-weight: 400;
    font-size: 12px;
    line-height: 45px;
    text-align: left;
    margin: 0 0 0 30px;
  }

  .component-listHeader .search-header .right {
    width: 70%;
    display: flex;
    justify-content: flex-end;
    margin-right: 30px;
  }

  .component-listHeader .search-header .right button {
    padding: 0 15px;
    height: 30px;
    margin: 6px 5px;
    line-height: 30px;
    font-size: 14px;
    color: #666;
    background-color: #fff;
    border: 1px solid #ccc;
  }

  .component-listHeader .search-header .right button:hover {
    background-color: #f3f3f3;
  }

  .component-listHeader .search-header .right .right-select-margin {
    margin-top: 6px;
    margin-right: 8px;
  }

  /* 删除按钮 */
  .red {
    color: #48c9b0;
    font-size: 12px;
  }
</style>
